import '../global_setting.dart';
import '../model/result_model.dart';
import '../model/semester_model.dart';
import '../utils/request.dart';

///学年学期 API
class SemesterApi {
  SemesterApi._();

  static final _signleton = SemesterApi._();

  factory SemesterApi() => _signleton;

  ///学年学期-分页查询
  Future<SemesterQueryRes> query(final SemesterQueryReq req) => request
      .getHandler(
        path: '/${globalSetting.tenant}/semester',
        params: req.toMap(),
      )
      .then((res) => SemesterQueryRes.fromModel(res));

  ///学年学期-加载
  Future<SemesterInfoRes> info(final String id) => request
      .getHandler(path: '/semester/$id')
      .then((res) => SemesterInfoRes.fromModel(res));

  ///学年学期-当前
  Future<SemesterInfoRes> current() => request
      .getHandler(path: '/semester/current')
      .then((res) => SemesterInfoRes.fromModel(res));

  ///学年学期-新增
  Future<BaseModelRes> add(final SemesterAddReq req) => request.postHandler(
      path: '/${globalSetting.tenant}/semester', data: req.toMap());

  ///学年学期-修改
  Future<BaseModelRes> modify(final SemesterModifyReq req) =>
      request.putHandler(path: '/semester/${req.id}', data: req.toMap());

  ///学年学期-删除
  Future<BaseModelRes> delete(final String id) =>
      request.deleteHandler(path: '/semester/$id');
}

///学年学期单例
final semesterApi = SemesterApi();
